package com.bz.portal.service.impl;

import com.bz.portal.feign.CommonItemFeignClient;
import com.bz.portal.feign.CommonRedisFeignClient;
import com.bz.portal.service.ItemCategoryService;
import com.bz.utils.Result;
import com.bz.vo.CatVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ItemCategoryServiceImpl implements ItemCategoryService {

    @Autowired
    private CommonItemFeignClient commonItemFeignClient;
    @Autowired
    private CommonRedisFeignClient commonRedisFeignClient;

    /**
     * 查询首页商品分类
     * @return
     */
    @Override
    public Result selectItemCategoryAll() {
        CatVo catVo;
        try {
            catVo = commonRedisFeignClient.selectItemCategory();
            if (catVo != null){
                return Result.ok(catVo);
            }
        } catch (Exception e) {
            log.error("【查询首页商品分类缓存失败】,{}",e);
        }
        catVo = commonItemFeignClient.selectItemCategoryAll();
        if (catVo != null){
            commonRedisFeignClient.insertItemCategory(catVo);
        }
        return Result.ok(catVo);
    }
}
